﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq.Expressions;
using System.Reflection;
using Framework.Attributes;
using Framework.Sql;

namespace Framework.Metadata
{
    public abstract class PropertyMetadataBase
    {
        public static PropertyMetadataBase FromProperty(PropertyInfo propertyInfo)
        {
            if (propertyInfo.IsDefined(typeof(ExcludeAttribute), false)) return null;
            if (new EntityMetadataFactory().CanHandleProperty(propertyInfo))
                return new EntityMetadata(propertyInfo);
            if (!new ColumnPropertyMetadataFactory().CanHandleProperty(propertyInfo))
                return new LazyLoadPropertyMetadata(propertyInfo);
            return new ColumnPropertyMetadata(propertyInfo);
        }

        public abstract void UpdateObject(object o, IDataRecord record, Func<Type, LambdaExpression, Action<SelectSqlBuilder, Type>, IEnumerable> find);
        public PropertyInfo PropertyInfo { get; protected set; }

        public virtual void SaveObject(Action<object, Action<InsertSqlBuilder>> saveMethod, object entity, Action<Type, PropertyInfo, int, IEnumerable<int>> delete = null)
        {
        }
    }
}